Ext.ns('Ext.ux.form');
Ext.ux.form.ObjectComboBox = Ext.extend(Ext.form.ComboBox,{
    forceSelection:true,
    setValue:function(v){
        if (Ext.isObject(v))
           v = v[this.valueField];
        var text = v;
        if(this.valueField){
            var r = this.findRecord(this.valueField, v);
            if(r){
                text = r.data[this.displayField];
            }else if(Ext.isDefined(this.valueNotFoundText)){
                text = this.valueNotFoundText;
            }
        }
        this.lastSelectionText = text;
        if(this.hiddenField){
            this.hiddenField.value = Ext.value(v, '');
        }
        Ext.form.ComboBox.superclass.setValue.call(this, text);
        this.value = v;
        return this;
    },
    getValue : function(){
        if(this.valueField){
        	var rec;
        	if (rec = this.findRecord(this.valueField, this.value))
        	   return Ext.isDefined(this.value) ? rec.data : '';
        	else
        	   return Ext.isDefined(this.value) ? this.value : '';
        }
        else
            return Ext.form.ComboBox.superclass.getValue.call(this);
    }
});

Ext.util.Observable.observeClass(Ext.ux.form.ObjectComboBox,{
    select:function(this_){
    	if (this_.gridEditor)
            this_.triggerBlur();
    }
});

Ext.reg('objectcombo', Ext.ux.form.ObjectComboBox);